<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员界面</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/axios.js"></script>
</head>
<body>
<h2>管理员页面</h2>
<hr>
<div id="app">
    <label>车位id</label><input v-model="id" type="number" value="">
    <hr>
    <button v-on:click="lock(id)">锁定该车位</button>
    <br>
    <button v-on:click="unlock(id)">解锁该车位</button>
    <hr>
    <button v-on:click="lockAll">锁定所有车位</button>
    <br>
    <button v-on:click="unlockAll">解锁所有车位</button>
    <hr>
    <button v-on:click="exit">退出登录</button>
</div>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            id: null
        },
        methods: {
            lock: function (id) {
                axios({
                    method: "post",
                    url: "http://localhost:8080/admin/lock",
                    params: {id: id}
                }).then(function (response) {
                    alert(response.data.msg);
                }, function (err) {
                    console.log(err);
                });
            },
            unlock: function (id) {
                axios({
                    method: "post",
                    url: "http://localhost:8080/admin/unlock",
                    params: {id: id}
                }).then(function (response) {
                    alert(response.data.msg);
                }, function (err) {
                    console.log(err);
                });
            },
            lockAll: function () {
                axios({
                    method: "post",
                    url: "http://localhost:8080/admin/lockAll",
                }).then(function (response) {
                    alert(response.data.msg);
                }, function (err) {
                    console.log(err);
                });
            },
            unlockAll: function () {
                axios({
                    method: "post",
                    url: "http://localhost:8080/admin/unlockAll",
                }).then(function (response) {
                    alert(response.data.msg);
                }, function (err) {
                    console.log(err);
                });
            },
            exit: function () {
                axios.get("http://localhost:8080/admin/exit").then(function (response) {
                    alert(response.data.msg);
                    if (response.data.flag) {
                        window.location.href = "http://localhost:8080/login.html";
                    }
                }, function (err) {
                    console.log(err);
                });
            }
        }
    });
</script>
</body>
</html>